﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace SFJDPopup
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        string message = null;
        TextBlock textBlock = null;

        public MainWindow(string str)
        {
            InitializeComponent();
            this.message = str;
            Ini();
        }

        public MainWindow(string[] args)
        {
            InitializeComponent();
            if(args.Length > 0)
            {
                this.message = args[1];
            }
            Ini();
        }

        private void Ini()
        {
            //初始化界面
            //this.Topmost = true;
            this.WindowStyle = WindowStyle.None;
            this.Loaded += MainWindow_Loaded;
            AllowsTransparency = true;
            Background = Brushes.Black;
            Opacity = 0.9;
            double ScreenWidth = SystemParameters.PrimaryScreenWidth;
            double ScreenHeigh = SystemParameters.PrimaryScreenHeight;
            Top = ScreenHeigh * 3 / 5;
            Left = 0;
            Height = ScreenHeigh / 5;
            Width = ScreenWidth;
            //初始化显示区域
            Grid layOutRoot = new Grid();
            layOutRoot.Width = ScreenWidth / 2;
            layOutRoot.HorizontalAlignment = HorizontalAlignment.Center;
            //layOutRoot.Background = Brushes.Pink;
            this.Content = layOutRoot;
            //添加标题
            Label label_Title = new Label();
            label_Title.FontSize = 30;
            label_Title.Foreground = Brushes.White;
            label_Title.Content = "通知：";
            layOutRoot.Children.Add(label_Title);
            //添加按钮
            TextBox textBox_Button = new TextBox();
            textBox_Button.BorderThickness = new Thickness(2);
            textBox_Button.HorizontalAlignment = HorizontalAlignment.Right;
            textBox_Button.VerticalAlignment = VerticalAlignment.Bottom;
            textBox_Button.TextAlignment = TextAlignment.Center;
            textBox_Button.Margin = new Thickness(0, 0, 10, 10);
            textBox_Button.IsReadOnly = true;
            textBox_Button.FontSize = 20;
            textBox_Button.Width = 100;
            textBox_Button.Foreground = Brushes.White;
            textBox_Button.Background = Brushes.DeepSkyBlue;
            textBox_Button.Text = "OK";
            textBox_Button.MouseEnter += TextBox_Button_MouseEnter;
            textBox_Button.MouseLeave += TextBox_Button_MouseLeave;
            textBox_Button.PreviewMouseDown += TextBox_Button_PreviewMouseDown;
            layOutRoot.Children.Add(textBox_Button);
            //添加显示区域
            textBlock = new TextBlock();
            textBlock.FontSize = 25;
            textBlock.Foreground = Brushes.White;
            textBlock.HorizontalAlignment = HorizontalAlignment.Left;
            textBlock.VerticalAlignment = VerticalAlignment.Top;
            textBlock.Margin = new Thickness(60, 60, 60, 60);
            textBlock.Text = this.message;
            layOutRoot.Children.Add(textBlock);
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Topmost = true;
        }

        private void TextBox_Button_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            Close();
            Environment.Exit(0);
            //Dispatcher.Thread.Abort();
            //Dispatcher.Thread.Join();
        }

        private void TextBox_Button_MouseLeave(object sender, MouseEventArgs e)
        {
            TextBox textBox = sender as TextBox;
            textBox.Background = Brushes.DeepSkyBlue;
            textBox.Foreground = Brushes.White;
            textBox.BorderBrush = Brushes.White;
        }

        private void TextBox_Button_MouseEnter(object sender, MouseEventArgs e)
        {
            TextBox textBox = sender as TextBox;
            textBox.Background = Brushes.LightSkyBlue;
            textBox.Foreground = Brushes.Black;
            //textBox.BorderBrush = Brushes.Black;
        }
    }
}
